/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package Tests;

import Entities.*;
import java.util.ArrayList;
import org.newdawn.slick.Color;
import org.newdawn.slick.GameContainer;
import org.newdawn.slick.Graphics;
import org.newdawn.slick.Image;
import org.newdawn.slick.Input;
import org.newdawn.slick.SlickException;
import org.newdawn.slick.state.StateBasedGame;

/**
 *
 * @author Shane
 */
public class Player {

    float x, y, rotation, rotateSpeed;
    double distX, distY;
    Image playerImage = null;

    public Player() throws SlickException {
        playerImage = new Image("data/plane.png");
        x = 100 + playerImage.getWidth()/2;
        y = 250 + playerImage.getHeight()/2;
        rotation = 0;
        rotateSpeed = 0;
    }

    public void update(GameContainer container, StateBasedGame game, int delta, ArrayList<Projectile> projectiles) throws SlickException {
        Input input = container.getInput();
        
        
        
        distX = input.getMouseX() - x;
        distY = input.getMouseY() - y;

        rotation = (float) Math.toDegrees(Math.atan(distY / distX)) + 90;
        
        if(distX < 0){
            rotation += 180;
        }
        playerImage.setRotation(rotation);
        
        if(input.isMousePressed(Input.MOUSE_LEFT_BUTTON)){
            System.out.println("Created Proj");
            Projectile tempProj = new Projectile(x - playerImage.getWidth()/2, y - playerImage.getHeight()/2, "data/plane.png", 5.0f, 5.0f, rotation);
            projectiles.add(tempProj);
        }
        
        
    }
    public void render(GameContainer container, Graphics g) throws SlickException {
        g.drawImage(playerImage, x - playerImage.getWidth()/2, y - playerImage.getHeight()/2);
  //      g.drawLine(x, y, x+(float)distX, y+(float)distY);
//        g.setColor(Color.red);
//        g.drawLine(x, y, x+(float)distX, y);
//        g.drawString("X: "+String.valueOf(distX), (x+(float)distX)/2, y);
//        g.setColor(Color.blue);
//        g.drawLine(x+(float)distX, y, x+(float)distX, y+(float)distY);
//        g.drawString("Y: "+String.valueOf(distY), x+(float)distX+5, (y+(float)distY/2));
//        g.setColor(Color.white);
//        g.drawString("A: "+String.valueOf(rotation), x-75, y);
        
    }
}
